#ifndef _COMM_KEY_H_
#define _COMM_KEY_H_
#include "soft_timer.h"

/*与按键电路有关,当按键按下为低电平时定义COMM_KEY_DOWN为0,否则交换定义*/
#define COMM_KEY_UP 1
#define COMM_KEY_DOWN 0

typedef int(*key_callback_func)(void*);

typedef enum {
	COMM_KEY_IDLE_STATUS =4,
	COMM_KEY_DOWN_STATUS =0,
	COMM_KEY_DOWN_SURE_STATUS =5,
	COMM_KEY_UP_STATUS =6,
	COMM_KEY_UP_SURE_STATUS =1,
	COMM_KEY_SHORT_PRESS =2,
	COMM_KEY_LONG_PRESS =3
}comm_key_status;

typedef struct{
	/*获取按键状态*/
	key_callback_func key_status_get_func;
	/*短按回调函数*/
	key_callback_func key_short_press_func;
	/*长按回调函数*/
	key_callback_func key_long_press_func;
	/*短按时间*/
	unsigned int short_press_time;
	/*长按时间*/
	unsigned int long_press_time;
	/*消抖时间*/
	unsigned int shake_time;
	/*消抖计时器*/
	TICK shake_timer;
	/*按下计时器*/
	TICK key_timer;
	/*按键状态*/
	comm_key_status key_status;
	/*按键是否已在使用*/
	uint8_t key_using_flag;
}keyInfo;


void key_InfoInit(void);
uint8_t key_Delete(keyInfo* key);
void key_HandleTask(void);
keyInfo* key_Create(key_callback_func keystatus,
					key_callback_func shortfunc,
					key_callback_func longfunc,
					uint32_t shorttime,
					uint32_t longtime,
					uint32_t shaketime);//消抖时间，一般为15ms

#endif // _COMM_KEY_H_

